package com.cms.manage;
import javax.servlet.MultipartConfigElement;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.cms.manage.util.MyMapper;

import springfox.documentation.swagger2.annotations.EnableSwagger2;
@ServletComponentScan 
@MapperScan(basePackages ="com.cms.manage.dao",markerInterface = MyMapper.class)
@SpringBootApplication
@EnableSwagger2
@Configuration
public class CmsManageApplication {

	public static void main(String[] args) {
		
		SpringApplication.run(CmsManageApplication.class, args);
	}

//	 @Bean
//	 public EmbeddedServletContainerCustomizer containerCustomizer(){
//	        return container -> {
//	              container.setSessionTimeout(10);/*单位为S*/
//	       };
//	 }
	
	// 解决跨域问题
	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurerAdapter() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**").allowedOrigins("*").allowedMethods("PUT", "DELETE", "GET", "POST")
						.allowedHeaders("*")
						.exposedHeaders("access-control-allow-headers", "access-control-allow-methods",
								"access-control-allow-origin", "access-control-max-age", "X-Frame-Options")
						.allowCredentials(false).maxAge(3600);
			}
		};

	}
	  /**
     * 文件上传配置
     * 
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //  单个数据大小
        factory.setMaxFileSize("102400KB"); // 100MB
        /// 总上传数据大小
        factory.setMaxRequestSize("1024000KB");// 1000MB
        return factory.createMultipartConfig();
    }

}
